package com.feige.service.impl;

import com.feige.pojo.UserRole;
import com.feige.dao.UserRoleMapper;
import com.feige.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用户角色表 服务实现类
 * </p>
 *
 * @author feige
 * @since 2020-07-20
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    @Override
    public List<Long> getRoleId(Long userId) {
        return baseMapper.getRoleId(userId);
    }

    @Override
    public boolean AssignRoles(Long userId, Long[] roleIds) {
        List<UserRole> userRoles = new ArrayList<>();
        for (Long roleId : roleIds) {
            UserRole userRole = new UserRole();
            userRole.setRoleId(roleId);
            userRole.setUserId(userId);
            userRoles.add(userRole);
        }
        return super.saveBatch(userRoles);
    }
}
